﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FundRaising.DAL;
using FundRaising.DAL._FR_DSTableAdapters;
using FundRaising.DAL._FR_DS_SmalParamTableAdapters;

namespace FundRaising.BLL
{
    public class RequestBLL
    {

        private RequestTableAdapter info = null;
        public RequestTableAdapter adapter
        {
            get
            {
                if (info == null) info = new RequestTableAdapter();
                return info;
            }
        }
        private Request1TableAdapter info1 = null;
        public Request1TableAdapter adapter1
        {
            get
            {
                if (info1 == null) info1 = new Request1TableAdapter();
                return info1;
            }
        }
        private Request2TableAdapter infoProj = null;
        public Request2TableAdapter ProjAdapter
        {
            get
            {
                if (infoProj == null) infoProj = new Request2TableAdapter();
                return infoProj;
            }
        }
        private Request3TableAdapter infoSub = null;
        public Request3TableAdapter SubAdapter
        {
            get
            {
                if (infoSub == null) infoSub = new Request3TableAdapter();
                return infoSub;
            }
        }
        private ReqConvTableAdapter conv = null;
        public ReqConvTableAdapter ConvAdapter
        {
            get
            {
                if (infoSub == null) conv = new ReqConvTableAdapter();
                return conv;
            }
        }

        private RequestFileTableAdapter Rfile = null;
        public RequestFileTableAdapter RequestFileadapter
        {
            get
            {
                if (Rfile == null) Rfile = new RequestFileTableAdapter();
                return Rfile;
            }
        }

        private AssoTableAdapter asso = null;
        public AssoTableAdapter AssoNameAd
        {
            get
            {
                if (asso == null) asso = new AssoTableAdapter();
                return asso;
            }
        }

        private Fund2TableAdapter Fund = null;
        public Fund2TableAdapter FundNameAd
        {
            get
            {
                if (Fund == null) Fund = new Fund2TableAdapter();
                return Fund;
            }
        }

        private FundRaising.DAL._FR_DS_SmalParamTableAdapters.AssoDomainTableAdapter Pro = null;
        public FundRaising.DAL._FR_DS_SmalParamTableAdapters.AssoDomainTableAdapter ProAd
        {
            get
            {
                if (Pro == null) Pro = new FundRaising.DAL._FR_DS_SmalParamTableAdapters.AssoDomainTableAdapter();
                return Pro;
            }
        }


        public DAL._FR_DS_SmalParam.AssoDomainDataTable GetProjByAsso(string AssoName)
        {
            return ProAd.GetProjectNameByAsso(AssoName);
        }

        public DAL._FR_DS_SmalParam.RequestDataTable GetProjByAssoName(string AssoName)
        {
            return ProjAdapter.GetProjByAsso(AssoName); 
        }


        public DAL._FR_DS_SmalParam.Fund2DataTable GetFundName()
        {
            return FundNameAd.GetFundName();
        }

        public DAL._FR_DS_SmalParam.AssoDataTable GetAssoName()
        {
            return AssoNameAd.GetAssoName();
        }









        public DAL._FR_DS.RequestFileDataTable GetFileByRequestKey(Guid RequestKey)
        {
            return RequestFileadapter.GetFileByRequestKey(RequestKey);
        }
        

        public void UpdateFileByFileId(string FileInfo, Guid Original_FileId, Guid FileId)
        {
            RequestFileadapter.UpdateFileByFileId(FileInfo, FileId);
        }

        public void DeleteFileByFileId(string FileInfo, Guid Original_FileId, Guid FileId)
        {
            RequestFileadapter.DeleteFileByFileId(FileId);
        }


        public void DeleteConv(string ConvInit, string ContactName, string Date, string ContMethod, string CovDescription, string Summery, Guid ConvKey)
        {
            //Guid Original_ConvKey = GUI.Extensions.RequestArchive.ConvKey;
            ConvAdapter.DeleteConv(ConvKey);
        }
        
        public void UpdateConv(string ConvInit, string ContactName, string Date, string ContMethod, string CovDescription, string Summery,Guid ConvKey)
        {
            //Guid Original_ConvKey = GUI.Extensions.RequestArchive.ConvKey;
            ConvAdapter.UpdateConv(ConvInit, ContactName, Date, ContMethod, CovDescription, Summery, ConvKey);
        }

        public DAL._FR_DS.ReqConvDataTable GetSelectedConv(object Conv2)
        {
            Guid ConvKey = GUI.Extensions.RequestArchive.ConvKey;
            return ConvAdapter.GetSelectedConv(ConvKey);
        }

        public void InsertReqConv(Guid FK,string ConvInit,string ContactName,string Date,string ContMethod,string CovDescription,string Summery)
        {
            ConvAdapter.InsertReqConv(FK, ConvInit, ContactName, Date, ContMethod, CovDescription, Summery);
        }
        public DAL._FR_DS.ReqConvDataTable GetConvByReqKey()
        {
            Guid FK = GUI.EditRequest.RequestKey;
            return ConvAdapter.GetConvByReqKey(FK);
        }

        public DAL._FR_DS_SmalParam.Request1DataTable getdata(string FundName)
        {
            return adapter1.GetData(FundName);
        }

        

        public DAL._FR_DS.RequestDataTable GetData()
        {
            return adapter.GetData();
        }

        public DAL._FR_DS.RequestDataTable GetRequestByKey()
        {
            return adapter.GetRequestByKey(GUI.EditRequest.RequestKey);
        }

        public DAL._FR_DS.RequestDataTable getDom(string FundName)
        {
            return adapter.Getdomainbyfund(FundName);
        }

        public DAL._FR_DS_SmalParam.Request2DataTable GetSubProj(String ProjectFLD)
        {
            return SubAdapter.GetSubByProj(ProjectFLD);
        }

        public DAL._FR_DS.RequestDataTable SearchRequest(string AssoName, string FundName, string ProjectFld, string RYear, string ActivetyFLD, string SubProj, string RStatus)
        {
            return adapter.SearchRequest(AssoName, FundName, ProjectFld, RYear, ActivetyFLD, SubProj, RStatus);
        }

        public int InsertNewRequest(string RYear, string AssoName, string ActivetyFLD, string FundName, string ProjectFld, string SubProj, string ForWhat, string SubmiMethod, float MoneyRequested, float MoneyExpected, string DateExpected, string RequestSntDate, string RStatus, string RequestKey)
        {                 
             RYear = GUI.NewRequest.ReqYear;
             AssoName = GUI.NewRequest.AssoName;
             FundName = GUI.NewRequest.FundName;
             ProjectFld = GUI.NewRequest.ProjName;
             ActivetyFLD = GUI.NewRequest.Domain;
             SubProj = GUI.NewRequest.Subproj;
            
            return adapter.InsertNewRequest(RYear, AssoName, ActivetyFLD, FundName, ProjectFld, SubProj, ForWhat, SubmiMethod, MoneyRequested, MoneyExpected, DateExpected, RequestSntDate, RStatus);

        }
                                                                         

        public void UpdateRequest(string RYear,string AssoName,string ActivetyFLD,string FundName,string ProjectFld,string SubProj,string ForWhat,string SubmiMethod,double MoneyRequested,double MoneyExpected,string DateExpected,string RequestSntDate,string RStatus,Guid Original_RequestKey)
        {
            Original_RequestKey = GUI.EditRequest.RequestKey;
            adapter.UpdateRequest(ForWhat, SubmiMethod, MoneyRequested, MoneyExpected, DateExpected,GUI.EditRequest.RequestKey,
                         RequestSntDate, RStatus, Original_RequestKey);
        }
    }
}
